package com.originskyseed.platform.base.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.originskyseed.platform.base.mapper.LogoMapper;
import com.originskyseed.platform.base.model.Logo;
import com.originskyseed.platform.base.service.ILogoService;
import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.util.bean.PrimaryKeyGeneratorUtil;

/**
 * logo信息表Service接口实现类（OSI_LOGO）
 *
 * @author wlj
 */
@DubboService
@Component("logoService")
public class LogoServiceImpl implements ILogoService {

	@Resource
	private LogoMapper logoMapper;

	/**
	 * 删除记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKey(String id) throws Exception {
		return this.logoMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 批量删除记录
	 *
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKeys(List<String> ids) throws Exception {
		return this.logoMapper.deleteByPrimaryKeys(ids);
	}

	/**
	 * 批量修改状态
	 *
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateDeleteByIds(List<String> ids) throws Exception {
		return this.logoMapper.updateDeleteByIds(ids);
	}

	/**
	 * 插入记录
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insert(Logo record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.logoMapper.insert(record);
	}

	/**
	 * 插入记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertSelective(Logo record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.logoMapper.insertSelective(record);
	}

	/**
	 * 更新记录
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKey(Logo record) throws Exception {
		record.setUpdateTime(new Date());
		return this.logoMapper.updateByPrimaryKey(record);
	}

	/**
	 * 更新记录（仅非空值字段）
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKeySelective(Logo record) throws Exception {
		record.setUpdateTime(new Date());
		return this.logoMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 批量修改状态
	 *
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateStateByIds(List<String> ids, int state) throws Exception {
		return this.logoMapper.updateStateByIds(ids, state);
	}

	/**
	 * 批量修改状态只显示一条
	 *
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateStateByIdsOnlyOne(List<String> ids) throws Exception {
		return this.logoMapper.updateStateByIdsOnlyOne(ids);
	}

	/**
	 * 只显示一条启用
	 *
	 * @param state
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateStateByIdOnlyOne(int state) throws Exception {
		return this.logoMapper.updateStateByIdOnlyOne(state);
	}

	/**
	 * 查询记录
	 *
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public Logo selectByPrimaryKey(String id) throws Exception {
		return this.logoMapper.selectByPrimaryKey(id);
	}

	/**
	 * 查询列表
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Logo> selectList(Logo record) throws Exception {
		return this.logoMapper.selectList(record);
	}

	/**
	 * 分页查询列表
	 *
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<Logo> selectListByPage(Map<String, Object> params, BasePage<Logo> page) throws Exception {
		params.put("page", page);
		List<Logo> list = this.logoMapper.selectListByPage(params);
		page.setResults(list);
		return page;
	}

	/**
	 * 查询单条数据
	 *
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public Logo selectByLogo(Logo record) throws Exception {
		return this.logoMapper.selectByLogo(record);
	}

}
